import { defineStore } from "pinia";

interface todoRaw {
    id:number,
    title:string,
    status:boolean
}

const useMainStore = defineStore('main',{
    state:()=>{
        return{
            todoList:[] as todoRaw[],
            allList:[] as todoRaw[]
        }
    },
    getters:{},
    actions:{
        add(value:todoRaw[]){
            this.todoList = value
            this.allList = value
        },
        //添加
        update(value:todoRaw){
            this.todoList.push(value)

        },
        //删除
        remove(value:any){
            this.todoList.splice(value,1)
        },
        //删除已选
        clear(arr:any){
            this.todoList = arr
            this.allList = arr

        },
        xuan(k:any){
            this.todoList[k].status = true
        
        },
        //正在进行中的
        act(){
            this.todoList = this.allList
            this.todoList = this.todoList.filter(item=>{
                return !item.status
            })
        },
        //已完成
        comp(){
            this.todoList = this.allList
            this.todoList = this.todoList.filter(item=>{
                return item.status
            })
        },
        //所有
        all(){
            this.todoList = this.allList
        }
    },
})
export {useMainStore}